package com.plian.system.service.hr.staff.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.plian.Tools.CollectionUtil;
import com.plian.system.entity.hr.staff.Train;
import com.plian.system.mapper.hr.staff.TrainMapper;
import com.plian.system.mybatis.base.BaseServiceImpl;
import com.plian.system.service.hr.staff.ITrainService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 近五年三个月以上培训情况 服务实现类
 *
 * @author gangan
 * @since 2019-11-12
 */
@Service
@AllArgsConstructor
public class TrainServiceImpl extends BaseServiceImpl<TrainMapper, Train> implements ITrainService {
	@Override
	public List<Train> ListByPid(Long pid) {
		return list(new LambdaQueryWrapper<Train>().eq(Train::getIsDeleted, 0).eq(Train::getStaffFilesId, pid));
	}

	@Override
	public Boolean deleteLogicStaffFilesId(List<Long> ids) {
		LambdaQueryWrapper<Train> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.in(Train::getStaffFilesId, ids);
		List<Train> trains = list(queryWrapper);
		if (CollectionUtil.isNotEmpty(trains)){
			return deleteLogic(trains.stream().map(Train::getId).collect(Collectors.toList()));
		}
		return true;
	}
}
